import 'package:flutter/material.dart';
import 'EssayListPage.dart';
import 'CalendarPage.dart';
import 'TalkPage.dart';
import 'TextPage.dart';
import 'main.dart';

class MenuPage extends StatefulWidget {
  List<String> data = ["首  页", "文  字", "声  音", "影  像", "谈  论", "单  向  历"];
  PageController controller;

  MenuPage({this.controller});

  @override
  State<StatefulWidget> createState() {
    return SettingState();
  }

}

class SettingState extends State<MenuPage> {
  static final int INDEX_ZERO = 0;
  static final int INDEX_ONE = 1;
  static final int INDEX_TWO = 2;
  static final int INDEX_THREE = 3;
  static final int INDEX_FOUR = 4;
  static final int INDEX_FIVE = 5;

  @override
  Widget build(BuildContext context) {
    return Container(
      color: Color(0xff313131),
      child: Column(
        children: <Widget>[
          Row(
            children: <Widget>[
              Container(
                width: 45,
                height: 45,
                margin: EdgeInsets.only(left: 8, top: 25),
                child: IconButton(
                    icon: Image.asset("image/icon_close.png"),
                    onPressed: () {
                      print("返回首页");
                      widget.controller.animateToPage(HomePage.PAGE_MAIN, duration: Duration(milliseconds: 1500), curve: ElasticOutCurve(2));
                    }
                )
              ),
              Expanded(
                child: Text(""),
              ),
              Container(
                width: 45,
                height: 45,
                margin: EdgeInsets.only(right: 8, top: 25),
                child: IconButton(
                  icon: Image.asset("image/icon_search.png"),
                  onPressed: () {

                  },
                )
              )
            ],
          ),
          Padding(
            padding: EdgeInsets.only(top: 15, bottom: 30),
            child: Text(
                "单读",
              style: TextStyle(
                color: Colors.white,
                fontSize: 20
              ),
            )
          ),
          Row(
            children: <Widget>[
              Expanded(
                flex: 2,
                child: Divider(color: Color(0xff505050)),
              ),
              Expanded(
                flex: 5,
                child: Text(
                  "W E  R E A D  T H E  W O R L D",
                  textAlign: TextAlign.center,
                  style: TextStyle(
                    color: Color(0xffD3D9D9)
                  ),
                ),
              ),
              Expanded(
                flex: 2,
                child: Divider(color: Color(0xff505050)),
              )
            ],
          ),
          Padding(padding: EdgeInsets.only(top: 15)),
          createWidget(widget.data[INDEX_ZERO], index: INDEX_ZERO),
          createWidget(widget.data[INDEX_ONE], index: INDEX_ONE),
          createWidget(widget.data[INDEX_TWO], index: INDEX_TWO),
          createWidget(widget.data[INDEX_THREE], index: INDEX_THREE),
          createWidget(widget.data[INDEX_FOUR], index: INDEX_FOUR),
          createWidget(widget.data[INDEX_FIVE], index: INDEX_FIVE),
          Padding(padding: EdgeInsets.only(bottom: 30)),
          Text(
              "Powered by owspace",
            style: TextStyle(
              color: Color(0xff757575),
              fontSize: 10
            ),
          )
        ],
      ),
    );
  }

  Widget createWidget(String title, {int index}) {
    var i = index;
    return GestureDetector(
      child: Padding(
          child: Text(title,
              style: TextStyle(
                  color: Colors.white,
                  fontSize: 32
              )
          ),
          padding: EdgeInsets.only(top: 25)
      ),
      onTap: () {
        if(i == INDEX_ZERO) {
          widget.controller.animateToPage(HomePage.PAGE_MAIN, duration: Duration(milliseconds: 1500), curve: ElasticOutCurve(2));
        } else if(i == INDEX_ONE) {
          Navigator.push(context, MaterialPageRoute(builder: (BuildContext context) => TextPage()));
        } else if(i == INDEX_TWO) {
          Navigator.push(context, MaterialPageRoute(builder: (BuildContext context) => EssayListPage(title: widget.data[INDEX_TWO], path: "json/VoiceData.json",)));
        } else if(i == INDEX_THREE) {
          Navigator.push(context, MaterialPageRoute(builder: (BuildContext context) => EssayListPage(title: widget.data[INDEX_THREE], path: "json/BlipData.json",)));
        } else if(i == INDEX_FOUR) {
          Navigator.push(context, MaterialPageRoute(builder: (BuildContext context) => TalkPage(title: widget.data[INDEX_FOUR],)));
        } else {
          Navigator.push(context, MaterialPageRoute(builder: (context) => CalendarPage(title: widget.data[INDEX_FIVE],)));
        }
      }
    );
  }
}